<!--
 * @Author: sundl
 * @Date: 2021-04-08 14:56:57
 * @project: 天津YQ平台
-->
<template>
  <el-row class>
    <ModuleCard>
      <template v-slot:header>
        <dg-row type="flex">
          <dg-col :span="2"><strong>基本信息</strong></dg-col>
          <dg-col>
            <dg-tag v-permission="['XXXX_LDGZ']" v-if="form.isLdgz === '1'" effect="dark" type="primary">
              其他领导关注
            </dg-tag>
            <dg-tag v-permission="['XXXX_JLDGZ']" v-if="form.isJldgz === '1'" effect="dark" type="success">
              局领导关注
            </dg-tag>
            <dg-tag effect="dark" v-if="form.signInVO" :type="form.signInVO.jjcd | filterTagType">
              <span v-translate="{ code: BM_JJCD, value: form.signInVO.jjcd }"></span>
            </dg-tag>
          </dg-col>
        </dg-row>
      </template>

      <!-- 基本信息 -->
      <detail-form :list="formFilds"> </detail-form>

      <!-- 附件 -->
      <ModuleCard>
        <template v-slot:header>附件</template>
        <dg-row>
          <Enclosure :files="form.fileHolderList" />
        </dg-row>
      </ModuleCard>
    </ModuleCard>
  </el-row>
</template>

<script>
import DetailForm from '@/components/detail-form';
import ModuleCard from '@/components/layout/module-card';
import Enclosure from '@/components/layout/enclosure';
import { getFlowDetail } from '@/api/common';
import { BM_JJCD } from '@/common/codeDic';
import { ExterCommunFields, defaultFields, noExterCommunFields, noDefaultFields } from './config.js';

export default {
  name: 'BaseInfo',
  props: {},
  components: {
    ModuleCard,
    Enclosure,
    DetailForm
  },
  computed: {
    flowId() {
      return this.$route.params.id;
    },
    detailType() {
      return this.$route.query.type;
    }
  },
  filters: {
    filterTagType(val) {
      const color = {
        1: 'danger',
        2: 'warning',
        3: 'primary'
      };
      return color[val];
    }
  },
  data() {
    return {
      ExterCommunFields,
      BM_JJCD,
      form: {},
      formFilds: []
    };
  },

  mounted() {},

  methods: {
    init() {
      this.fetchDetail();
    },
    fetchDetail() {
      getFlowDetail(this.flowId).then((res) => {
        this.form = JSON.parse(JSON.stringify(res.data));
        console.log('shujv111', this.form);
        // 来源类型：0-外部来文；1-要情上报；2-线索上报；3-110报警信息（情报）-研判；4-线索（情报特有）；5-110报警处理（续报）
        // const fields = this.form.sourceType === '0' ? ExterCommunFields : defaultFields;

        let fields="";
        if (this.form.sourceType === '0' && this.form.xxlbCode == '101001') {
          // 外部来文-详情 && 信息类别为“预警线索”
          fields = ExterCommunFields;
        } else if (this.form.sourceType === '0' && this.form.xxlbCode != '101001') {
          // 外部来文-详情 && 信息类别不为“预警线索”
          fields = noExterCommunFields;
        } else if (this.form.sourceType != '0' && this.form.xxlbCode == '101001') {
          // 非外部来文-详情 && 信息类别为“预警线索”
          fields = defaultFields;
        } else {
          // 非外部来文-详情 && 信息类别不为“预警线索”
          fields = noDefaultFields;
        }

        // 基本信息
        let infoCols = JSON.parse(JSON.stringify(fields));
        infoCols.flatMap((item) => {
          item.forEach((cItem) => {
            if (cItem.field == 'sjqtCode' && this.form[cItem.field]) {
              cItem.value = this.form[cItem.field].split(',');
            } else {
              cItem.value = this.form[cItem.field];
            }
          });
        });
        this.formFilds = infoCols;
        console.log('shujv', this.formFilds);
        this.$emit('updateBaseInfo', this.form);
      });
    }
  },
  created() {
    this.init();
  }
};
</script>

<style lang="scss" scoped>
.wrap {
  .info-title {
    margin-bottom: 20px;
  }
  .item-radio {
    height: 20px;
    align-self: center;
    margin-left: 8px;
  }
  &-title {
    font-weight: bolder;
    margin-bottom: 10px;
  }
  &-upload {
    margin-bottom: 20px;
    /deep/.el-upload {
      display: none;
    }
  }

  /deep/.el-form-item {
    margin-bottom: 5px;
  }
}

/deep/.el-date-editor.el-input {
  width: 100%;
}
</style>
